package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketAdmin;
import com.cskaoyan.market.db.domain.MarketAdminExample;
import com.cskaoyan.market.db.mapper.MarketAdminMapper;
import com.cskaoyan.market.service.AdminAuthService;
import com.cskaoyan.market.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

public class AdminAuthServiceImpl implements AdminAuthService {
    @Override
    public MarketAdmin login(String username, String password) {
        //调用mybatis
//        AdminAuthServiceImpl.class.getClassLoader().getResourceAsStream()
        SqlSession sqlSession = MybatisUtil.getSession();
        MarketAdminMapper adminMapper = sqlSession.getMapper(MarketAdminMapper.class);
        MarketAdminExample marketAdminExample = new MarketAdminExample();
        //拼接查询条件的
        MarketAdminExample.Criteria criteria = marketAdminExample.createCriteria();
        criteria.andUsernameEqualTo(username);
        criteria.andPasswordEqualTo(password);
        MarketAdmin admin = adminMapper.selectOneByExample(marketAdminExample);
        sqlSession.commit();
        sqlSession.close();
        return admin;
    }
}
